<template>
	<view class="container backFFF">		
		<view class="ble-wrap pa">
			<view class="ble-ul pa">
				<view class="ble-li flex-wrap-between"  v-for="(item,index) in bleList" :key="index">
					<view class="ble-device-wrap"><view>{{item.localName}}</view>
					<view>{{item.deviceId}}</view></view>
					<view class="connect btn " @click="connect" :data-mac="item.deviceId" :data-name="item.localName">连接</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '设备列表',
				bleList:[]
			}
		},
		onLoad() {
						
		},
		methods: {
			recvbleList(res){
				//接收设备列表
				// console.log('设备列表',res)
				if(res.errMsg == 'getBluetoothDevices:ok'){
					//处理数据
					let deviceArr = [];
					for(let i=0;i<res.devices.length;i++){					
						if(res.devices[i].localName){							
							// if(res.devices[i].localName.indexOf('AMISL') != -1){
								deviceArr.push(res.devices[i]);
							// }
						}
					}
					this.bleList = deviceArr;
				}
			},
			connect(e){
				var mac = e.currentTarget.dataset.mac;
				var name = e.currentTarget.dataset.name;
				
				this.$ble.connect(mac,name);
			}
		}
	}
</script>

<style>
	
	.ble-wrap{
	  left: 0;
	  right: 0;
	  bottom: 0;
	  overflow: hidden;
	  top: 0;
	}
	.ble-ul{
	  top: 0;
	  left: 30rpx;
	  right: 30rpx;
	  bottom: 0;
	  overflow: auto;
	}
	.ble-li{
	  padding: 30rpx 6rpx;
	  border-bottom: 1px solid #DCDCDC;
	}
	.ble-li .btn{
	  font-size:27rpx;
	  height: 54rpx;
	  line-height: 54rpx;
	  width: 135rpx;
	  margin-top: 18rpx;
	}
	.ble-li .btn.on{
	  background: red;
	}
	.ble-device-wrap span{
	  display: block;
	  height: 45rpx;
	  line-height: 45rpx;
	}
	.ble-device-wrap span:first-child{
	  font-size: 33rpx;
	  font-weight: 500;
	  color: #181818;
	
	}
	.ble-device-wrap span:last-child{
	  font-size:27rpx;
	  color: #515151;
	}
</style>
